package com.cosmoplat.mom.iot.client.http;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author yotta
 * @date 2025/4/15 18:22
 */
@Getter
@EqualsAndHashCode
@Setter
public class Parameter {

    private String name;
    private String value;

    public Parameter(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public String asUrlEncodedPair() {
        String name = this.getName();
        String encodedSearchTerm = getEncodeValue();
        return name.concat("=").concat(encodedSearchTerm);
    }
    public String getEncodeValue() {
        try {
            return URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}
